import Vue from 'vue';
import Router from 'vue-router';
// 公共css
import '@/style/common.css';

// 登录
import login from '@/page/login/login';

// 公共框架
import index from '@/page/index/index';

// 管理中心首页
import adminindex from '@/page/index/adminindex';

// 支付订单
import ordinaryOrder from '@/page/ordinaryOrder/ordinaryOrder';

// 支付订单详情
import ordinaryOrderDetails from '@/page/ordinaryOrder/ordinaryOrderDetails';

// 预授权订单
import authOrder from '@/page/authOrder/authOrder';

// 预授权订单详情
import authOrderDetails from '@/page/authOrder/authOrderDetails';

// 商家列表
import storeList from '@/page/store/store-list';

// 商户设置
import storeSet from '@/page/store/store-set';

// 添加商户
import addStore from '@/page/store/add-store';

// 商户基础信息设置
import setStore from '@/page/store/set-store';

// 员工管理
import cashierList from '@/page/cashier/cashier-list';

// 员工详情
import cashierdetails from '@/page/cashier/cashierdetails';

// 添加员工
import addcashier from '@/page/cashier/addcashier';

// 支付业务设置
import payment from '@/page/store/payment';

// 支付业务设置
import storeinfo from '@/page/store/store-info';

// 聚合收款码
import mergepayqr from '@/page/store/merge-pay-qr';

// 业务开通
import setService from '@/page/store/set-service';

// 商家-支付通道实例
import paywayscaselist from '@/page/store/payways-case-list';

// 商家-添加支付通道实例
import paywayscaseadd from '@/page/store/payways-case-add';

// 商家-支付通道实例详情
import paywayscasedetails from '@/page/store/payways-case-details';

// 数据报表相关-----------------------------------------------
// 服务商报表
import isvTable from '@/page/data-analysis/isv-table';

// 商家报表
import storeTable from '@/page/data-analysis/store-table';

// 入驻分析
import storeEnterNalysis from '@/page/data-analysis/store-enter-nalysis';

// 系统日志相关---------------------------------------------
// 错误日志
import errorLog from '@/page/log/error-log';

// 错误日志详情
import errorLogDetail from '@/page/log/error-log-detail';

// 行为日志
import behaviorLog from '@/page/log/behavior-log';

// 行为日志详情
import behaviorLogDetail from '@/page/log/behavior-log-detail';

// 接口日志
import apiLog from '@/page/log/api-log';

// 分销-人员管理
import memberlist from '@/page/member/memberlist';

// 分销-人员详情
import memberdetails from '@/page/member/memberdetails';

// 分销-添加人员
import addmember from '@/page/member/addmember';

// 分佣-收支明细
import JournalAccount from '@/page/brokerage/JournalAccount';

// 分佣-提现记录
import WithdrawList from '@/page/brokerage/WithdrawList';

// 分佣-提现记录详情
import WithdrawDetails from '@/page/brokerage/WithdrawDetails';

// 分佣-申请提现
import AddWithdraw from '@/page/brokerage/AddWithdraw';

// 系统配置-ISV支付
import isvconfig from '@/page/systemconfig/isvconfig';

// 系统配置-短信服务
import smsconfig from '@/page/systemconfig/smsconfig';

// 系统配置-云打印
import printconfig from '@/page/systemconfig/printconfig';

// 系统配置-网站信息
import webconfig from '@/page/systemconfig/webconfig';

// 首页
import home from '@/page/index/home';

// 菜单管理相关
// 菜单管理
import menuManage from '@/page/menu/menu-manage';

// 个人资料
import personalconfig from '@/page/menu/personalconfig';

// 提现设置
import withdrawconfig from '@/page/menu/withdrawconfig';

// 角色管理
import roles from '@/page/menu/roles';

// 角色权限设置
import rolerightseditor from '@/page/user/role-rights-editor';

// 监控-系统运行
import sysrun from '@/page/monitor/sysrun';

// 监控-支付交易
import paytrade from '@/page/monitor/paytrade';

// 硬件-易联云
import elianyun from '@/page/hardware/elianyun';

// 硬件-悉点
import xidian from '@/page/hardware/xidian';

// 硬件-盛和
import shenghe from '@/page/hardware/shenghe';

// 硬件-商米POS机
import shangmi from '@/page/hardware/shangmi';

// 添加网商银行配置
import internetBankAddSet from '@/page/store/internet-bank-add-set';

// 网商银行入驻列表
import internetBankList from '@/page/store/internet-bank-list';

// 网商银行详情
import internetBankListDetails from '@/page/store/internet-bank-list-details';

// 网商银行添加子商户
import internetBankAddChildrenMerchant from '@/page/store/internet-bank-add-children-merchant';

// 网商银行
import internetBankListModify from '@/page/store/internet-bank-list-modify';

// 网商银行进度查询
import internetBankScheduleQuery from '@/page/store/internet-bank-schedule-query';

// isv 配置列表
import isvconfiglist from '@/page/isvmanage/isvconfiglist';

// 自定义组件-----------------------------------------------
// 面包屑导航
import breadcrumb from '@/components/breadcrumb/breadcrumb';

// 输入框组件
import tzInput from '@/components/tz-input/tz-input';

// 前端demo
import demo from '@/page/demo/demo';

// 404页面
import notFound from '@/page/not-found/not-found';

// echarts自定义组件-----------------------------------------------
// 饼图组件
import pie from '@/components/echarts/pie';
// 环形饼图组件
import circularpie from '@/components/echarts/circularpie';
// 柱状图组件
import histogram from '@/components/echarts/histogram';
// 折线图组件
import brokenline from '@/components/echarts/brokenline';
// k线图组件
import kline from '@/components/echarts/kline';

Vue.use(Router);

let router = {
  routes: [
    {
      // 登录
      path: '/',
      name: 'login',
      component: login
    },
    {
      // 登录
      path: '/login',
      name: 'login',
      component: login
    },
    {
      path: '/index',
      name: 'index',
      component: index,
      meta: {
        keepAlive: true,
        requireAuth: true
      },
      children: [
        {
          path: '/adminindex',
          name: 'adminindex',
          meta: {
            requireAuth: true
          },
          component: adminindex
        },
        {
          path: '/ordinaryOrder',
          name: 'ordinaryOrder',
          meta: {
            requireAuth: true
          },
          component: ordinaryOrder
        },
        {
          // 支付订单
          path: '/ordinaryOrder',
          name: 'ordinaryOrder',
          meta: {
            requireAuth: true
          },
          component: ordinaryOrder
        },
        {
          // 支付订单详情
          path: '/ordinaryOrderDetails',
          name: 'ordinaryOrderDetails',
          meta: {
            requireAuth: true
          },
          component: ordinaryOrderDetails
        },
        {
          // 预授权订单
          path: '/authOrder',
          name: 'authOrder',
          meta: {
            requireAuth: true
          },
          component: authOrder
        },
        {
          // 预授权订单详情
          path: '/authOrderDetails',
          name: 'authOrderDetails',
          meta: {
            requireAuth: true
          },
          component: authOrderDetails
        },
        {
          // 商户列表
          path: '/store-list',
          name: 'store-list',
          meta: {
            requireAuth: true
          },
          component: storeList
        },
        {
          path: '/store-set',
          name: 'store-set',
          meta: {
            requireAuth: true
          },
          component: storeSet,
          children: [
            {
              path: '/',
              name: 'set-store',
              meta: {
                requireAuth: true
              },
              component: setStore
            },
            {
              // 店铺设置
              path: '/set-store',
              name: 'set-store',
              meta: {
                requireAuth: true
              },
              component: setStore
            },
            {
              // 支付业务设置
              path: '/payment',
              name: 'payment',
              meta: {
                requireAuth: true
              },
              component: payment
            },
            {
              // 聚合收款码
              path: '/merge-pay-qr',
              name: 'merge-pay-qr',
              component: mergepayqr
            },
            {
              // 商户详细资料
              path: '/store-info',
              name: 'store-info',
              meta: {
                requireAuth: true
              },
              component: storeinfo
            }
          ]
        },
        {
          // 员工列表
          path: '/cashier-list',
          name: 'cashier-list',
          meta: {
            requireAuth: true
          },
          component: cashierList
        },
        {
          // 员工详情
          path: '/cashierdetails',
          name: 'cashierdetails',
          meta: {
            requireAuth: true
          },
          component: cashierdetails
        },
        {
          // 添加员工
          path: '/addcashier',
          name: 'addcashier',
          meta: {
            requireAuth: true
          },
          component: addcashier
        },
        {
          // 服务设置
          path: '/set-service',
          name: 'set-service',
          meta: {
            requireAuth: true
          },
          component: setService
        },
        {
          // 商家 - 添加支付通道实例
          path: '/payways-case-add',
          name: 'payways-case-add',
          meta: {
            requireAuth: true
          },
          component: paywayscaseadd
        },
        {
          // 商家 - 支付通道实例列表
          path: '/payways-case-list',
          name: 'payways-case-list',
          meta: {
            requireAuth: true
          },
          component: paywayscaselist
        },
        {
          // 商家 - 支付通道实例详情
          path: '/payways-case-details',
          name: 'payways-case-details',
          meta: {
            requireAuth: true
          },
          component: paywayscasedetails
        },
        {
          // 服务商报表
          path: '/isv-table',
          name: 'isv-table',
          meta: {
            requireAuth: true
          },
          component: isvTable
        },
        {
          // 商家报表
          path: '/store-table',
          name: 'store-table',
          meta: {
            requireAuth: true
          },
          component: storeTable
        },
        {
          // 入驻分析
          path: '/store-enter-nalysis',
          name: 'store-enter-nalysis',
          meta: {
            requireAuth: true
          },
          component: storeEnterNalysis
        },
        {
          // 错误日志
          path: '/error-log',
          name: 'error-log',
          meta: {
            requireAuth: true
          },
          component: errorLog
        },
        {
          // 错误日志详情
          path: '/error-log-detail',
          name: 'error-log-detail',
          meta: {
            requireAuth: true
          },
          component: errorLogDetail
        },
        {
          // 入驻分析
          path: '/api-log',
          name: 'api-log',
          meta: {
            requireAuth: true
          },
          component: apiLog
        },
        {
          // 入驻分析
          path: '/behavior-log',
          name: 'behavior-log',
          meta: {
            requireAuth: true
          },
          component: behaviorLog
        },
        {
          // 入驻分析详情
          path: '/behavior-log-detail',
          name: 'behavior-log-detail',
          meta: {
            requireAuth: true
          },
          component: behaviorLogDetail
        },
        {
          // 菜单管理
          path: '/menu-manage',
          name: 'menu-manage',
          meta: {
            requireAuth: true
          },
          component: menuManage
        },
        {
          // 个人资料
          path: '/personalconfig',
          name: 'personalconfig',
          meta: {
            requireAuth: true
          },
          component: personalconfig
        },
        {
          // 角色管理
          path: '/roles',
          name: 'roles',
          meta: {
            requireAuth: true
          },
          component: roles
        },
        {
          // 角色权限设置
          path: '/rolerightseditor',
          name: 'rolerightseditor',
          meta: {
            requireAuth: true
          },
          component: rolerightseditor
        },
        {
          // 提现设置
          path: '/withdrawconfig',
          name: 'withdrawconfig',
          meta: {
            requireAuth: true
          },
          component: withdrawconfig
        },
        {
          // 人员管理
          path: '/memberlist',
          name: 'memberlist',
          meta: {
            requireAuth: true
          },
          component: memberlist
        },
        {
          // 人员详情
          path: '/memberdetails',
          name: 'memberdetails',
          meta: {
            requireAuth: true
          },
          component: memberdetails
        },
        // 添加商户
        {
          path: '/add-store',
          name: 'add-store',
          meta: {
            requireAuth: true
          },
          component: addStore
        },
        // 添加网商银行配置
        {
          path: '/internet-bank-add-set',
          name: 'internet-bank-add-set',
          meta: {
            requireAuth: true
          },
          component: internetBankAddSet
        },
        // 网商入驻列表
        {
          path: '/internet-bank-list',
          name: 'internet-bank-list',
          meta: {
            requireAuth: true
          },
          component: internetBankList
        },
        // 网商入驻列表详情
        {
          path: '/internet-bank-list-details',
          name: 'internet-bank-list-details',
          meta: {
            requireAuth: true
          },
          component: internetBankListDetails
        },
        // 网商银行添加子商户
        {
          path: '/internet-bank-add-children-merchant',
          name: 'internet-bank-add-children-merchant',
          meta: {
            requireAuth: true
          },
          component: internetBankAddChildrenMerchant
        },
        // 网商银行修改
        {
          path: '/internet-bank-list-modify',
          name: 'internet-bank-list-modify',
          meta: {
            requireAuth: true
          },
          component: internetBankListModify
        },
        // 网商银行进度查询
        {
          path: '/internet-bank-schedule-query',
          name: 'internet-bank-schedule-query',
          meta: {
            requireAuth: true
          },
          component: internetBankScheduleQuery
        },
        {
          // 添加人员
          path: '/addmember',
          name: 'addmember',
          meta: {
            requireAuth: true
          },
          component: addmember
        },
        {
          // 收支明细
          path: '/JournalAccount',
          name: 'JournalAccount',
          meta: {
            requireAuth: true
          },
          component: JournalAccount
        },
        {
          // 提现记录
          path: '/WithdrawList',
          name: 'WithdrawList',
          meta: {
            requireAuth: true
          },
          component: WithdrawList
        },
        {
          // 提现记录详情
          path: '/WithdrawDetails',
          name: 'WithdrawDetails',
          meta: {
            requireAuth: true
          },
          component: WithdrawDetails
        },
        {
          // 申请提现
          path: '/AddWithdraw',
          name: 'AddWithdraw',
          meta: {
            requireAuth: true
          },
          component: AddWithdraw
        },
        {
          // 系统配置-ISV支付
          path: '/isvconfig',
          name: 'isvconfig',
          meta: {
            requireAuth: true
          },
          component: isvconfig
        },
        {
          // 系统配置-短信服务
          path: '/smsconfig',
          name: 'smsconfig',
          meta: {
            requireAuth: true
          },
          component: smsconfig
        },
        {
          // 系统配置-云打印
          path: '/printconfig',
          name: 'printconfig',
          meta: {
            requireAuth: true
          },
          component: printconfig
        },
        {
          // 系统配置-网站信息
          path: '/webconfig',
          name: 'webconfig',
          meta: {
            requireAuth: true
          },
          component: webconfig
        },
        {
          // 监控-系统运行
          path: '/sysrun',
          name: 'sysrun',
          meta: {
            requireAuth: true
          },
          component: sysrun
        },
        {
          // 监控-支付交易
          path: '/paytrade',
          name: 'paytrade',
          meta: {
            requireAuth: true
          },
          component: paytrade
        },
        {
          // 硬件-易联云
          path: '/elianyun',
          name: 'elianyun',
          meta: {
            requireAuth: true
          },
          component: elianyun
        },
        {
          // 硬件-悉点
          path: '/xidian',
          name: 'xidian',
          meta: {
            requireAuth: true
          },
          component: xidian
        },
        {
          // 硬件-盛和
          path: '/shenghe',
          name: 'shenghe',
          meta: {
            requireAuth: true
          },
          component: shenghe
        },
        {
          // 硬件-商米POS机
          path: '/shangmi',
          name: 'shangmi',
          meta: {
            requireAuth: true
          },
          component: shangmi
        },
        { // echarts组件--------------------------------------------
          // 饼图
          path: '/pie',
          name: 'pie',
          meta: {
            requireAuth: true
          },
          component: pie
        },
        {
          // 环形饼图
          path: '/circularpie',
          name: 'circularpie',
          meta: {
            requireAuth: true
          },
          component: circularpie
        },
        {
          // 柱状图
          path: '/histogram',
          name: 'histogram',
          meta: {
            requireAuth: true
          },
          component: histogram
        },
        {
          // 折线图
          path: '/brokenline',
          name: 'brokenline',
          meta: {
            requireAuth: true
          },
          component: brokenline
        },
        {
          // k线图
          path: '/kline',
          name: 'kline',
          meta: {
            requireAuth: true
          },
          component: kline
        },
        {
          path: '/',
          name: 'home',
          // 添加该字段，表示进入这个路由是需要登录的
          meta: {
            requireAuth: true
          },
          component: home
        },
        {
          path: '/home',
          name: 'home',
          // 添加该字段，表示进入这个路由是需要登录的
          meta: {
            requireAuth: true
          },
          component: home
        },
        { // 前端demo
          // k线图
          path: '/demo',
          name: 'demo',
          meta: {
            requireAuth: true
          },
          component: demo
        },
        {
          // isv 配置列表
          path: '/isvconfiglist',
          name: 'isvconfiglist',
          meta: {
            requireAuth: true
          },
          component: isvconfiglist
        },
        {
          // 404页面
          path: '/404',
          name: '404',
          meta: {
            requireAuth: true
          },
          component: notFound
        }
      ]
    },
    {
      // 导航栏
      path: '/breadcrumb',
      name: 'breadcrumb',
      meta: {
        requireAuth: true
      },
      component: breadcrumb
    },
    {
      // input组件
      path: '/tzInput',
      name: 'tzInput',
      meta: {
        requireAuth: true
      },
      component: tzInput
    },
    {
      path: '*',
      redirect: '/404',
      hidden: true
    }
  ]
};

const routerOption = new Router({
  history: true,
  routes: router.routes
});

routerOption.beforeEach((to, from, next) => {
  // 判断该路由是否需要登录权限
  if (to.meta.requireAuth) {
    // 通过vuex state获取当前的token是否存在
    if (localStorage.getItem('token')) {
      next();
    } else {
      next({
        path: '/login'
      });
    }
  } else {
    next();
  };
});

export default routerOption;
